//
//  DZTabBar.m
//  Weico
//
//  Created by 大泽 on 15/7/21.
//  Copyright (c) 2015年 刘洪泽. All rights reserved.
//

#import "DZTabBar.h"

@interface DZTabBar ()
@property (nonatomic, weak) UIButton *plusBtn;

@end

@implementation DZTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 添加一个按钮到tabbar中
        UIButton *plusBtn = [[UIButton alloc] init];
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        plusBtn.size = plusBtn.currentBackgroundImage.size;
        [plusBtn addTarget:self action:@selector(plusClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:plusBtn];
        self.plusBtn = plusBtn;
    }
    return self;
}

- (void)plusClick
{
    DZLog(@"btnClick");
}

- (void)layoutSubviews{
    
    [super layoutSubviews];

    self.plusBtn.centerX = self.width * 0.5;
    self.plusBtn.centerY = self.height * 0.5;
    
    CGFloat w = self.width / 5;
    
    int index = 0;
    for (UIView *child in self.subviews) {
        
        Class class = NSClassFromString(@"UITabBarButton");
        
        if ([child isKindOfClass:class]) {
            
            child.x = index * w;
            
            index ++;
            
            if (index == 2) {
                index++;
            }
            
        }
    }
    
}

@end
